package org.example.stack;

/**
 * @author liyishan
 * @date 2024/10/9 16:13
 * @apiNote
 */

public class StackByArray {
    private int top = -1;
    private int maxSize;
    private int[] stack;

    public StackByArray(int size) {
        maxSize = size;
        stack = new int[maxSize];
    }
    public boolean isFull(){
        return top == maxSize - 1;
    }
    public boolean isEmpty(){
        return top == -1;
    }
    public void push(int data){
        if(isFull()){
            return;
        }
        stack[++top] = data;
    }
    public int pop(){
        if(isEmpty()){
            throw new RuntimeException("Stack is empty");
        }
        int data = stack[top--];
        return data;
    }
}
